Skip to content

Fix Combobox click-outside behavior for non-primitive values#193

Merged
GavinJoyce merged 1 commit into
masterfrom
gj/fix-combobox-original-value
Dec 20, 2025
Merged

Fix Combobox click-outside behavior for non-primitive values#193
GavinJoyce merged 1 commit into
masterfrom
gj/fix-combobox-original-value

Conversation

@GavinJoyce

@GavinJoyce GavinJoyce commented Dec 20, 2025

Copy link
Copy Markdown
Owner

Summary

Fixes #188 - Combobox now correctly preserves selected values when clicking outside after selecting a non-primitive option.

Root Cause

In handleOptionClick, setSelectedOption was called before onChange, so this.args.value hadn't been updated yet when trying to store it in _originalValue.

Changes

  • Swap order in -option.js: call onChange first, then setSelectedOption
  • This is consistent with the Enter key path which already calls setActiveAsSelected (triggering onChange) before setSelectedOption
  • Also set inputValue in setSelectedOption so the input immediately reflects the selection
  • Added test from PR TEST: for reproducing an issue with value set on outside click #189

Testing

  1. Render a Combobox with object values and a displayValue function
  2. Start with a null initial value
  3. Select an option from the list
  4. ✅ The input should immediately show the display value
  5. Open the combobox again
  6. Click outside the component
  7. ✅ The selected value should be preserved (previously it would revert to null)

@GavinJoyce GavinJoyce force-pushed the gj/fix-combobox-original-value branch from eef168c to 986e9f6 Compare December 20, 2025 11:21
Fixes #188 - Combobox now correctly preserves selected values when
clicking outside after selecting a non-primitive option.

Root cause: In handleOptionClick, setSelectedOption was called before
onChange, so this.args.value hadn't been updated yet.

Changes:
- Swap order in -option.js: call onChange first, then setSelectedOption
- Set inputValue in setSelectedOption so input immediately reflects selection
- Add test from PR #189 for non-primitive values with displayValue
@GavinJoyce GavinJoyce force-pushed the gj/fix-combobox-original-value branch from 986e9f6 to aa9fe11 Compare December 20, 2025 11:24
@GavinJoyce GavinJoyce merged commit be3df83 into master Dec 20, 2025
12 checks passed
@GavinJoyce GavinJoyce deleted the gj/fix-combobox-original-value branch December 20, 2025 11:28
@GavinJoyce GavinJoyce added the bug Something isn't working label Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<Combobox /> sets wrong values on click outside for non-primitive values and displayValue fallback

1 participant